package resturant;

import java.io.File;
import java.io.IOException;
import java.util.Dictionary;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;


public class OrdersList {

	
	private TreeMap<OrderItem, String> Order;
	
	public OrdersList() {
		Order = new TreeMap<OrderItem, String> ();
	}
		
	public void process(String filename){

		//read input file and create concordance
		String currentpath = "D:\\F21AS Resturant\\src\\resturant\\";
		readAndCreate(currentpath+ filename);  
	}
	
	private void readAndCreate(String filename) {
		Scanner lineScanner; 
		int lineNum = 1;  // The number of the line in the input

		try {  
			// read and process each line in the input file
			lineScanner = new Scanner(new File(filename));
			while (lineScanner.hasNext()){
				processLine(lineScanner.nextLine());
				lineNum++;  // inc line number
			}
		}
		catch (IOException e) {
			System.out.println("Error: Can't open input file ");
			System.exit(1);
		}
	}
      

	/*
	 * Separate out each word in the line
	 * and add these to the reference     
	 */
	private void processLine(String line) {
		String[] words = line.split(",");
		
		if (words.length != 3){
			//TODO: Throw Exception
			System.out.println("Incorrect Orders input with :"+ words.length);
			System.exit(0);
		}
		
		String tableNumber = words[0].toLowerCase().split("table")[1].trim();
		OrderItem value = new OrderItem(Integer.parseInt(tableNumber),words[1],Integer.parseInt(words[2]));
		
		//if (Order.contains(m)){
			//TODO: Throw Exception
	//		System.out.println("Duplicate Key on:"+ tableNumber +"&&"+ value.getOrderName());
	//		System.exit(0);
		//}
			Order.put(value,tableNumber);		 	  	
	}

public TreeMap<OrderItem, String> GetOrders(){
	
	return Order;
	}
}
